use std::fs;

const FILE_NAME: &'static str = "./memory.x";

pub fn create(flash: u32, flash_size: u32, ram: u32, ram_size: u32) {
    let content = format!(
        r#"
MEMORY {{
    FLASH : ORIGIN = 0x{:08x}, LENGTH = {}
    RAM : ORIGIN = 0x{:08x}, LENGTH = {}
}}
PROVIDE(SysTick = SysTick_Handler);
PROVIDE(SVCall = SVC_Handler);
PROVIDE(PendSV = PendSV_Handler);
    "#,
        flash, flash_size, ram, ram_size
    );
    fs::write(FILE_NAME, content).unwrap();
}

pub fn create_raw(flash: u32, flash_size: u32, ram: u32, ram_size: u32) {
    let content = format!(
        r#"
MEMORY {{
    FLASH : ORIGIN = 0x{:08x}, LENGTH = {}
    RAM : ORIGIN = 0x{:08x}, LENGTH = {}
}}
"#,
        flash, flash_size, ram, ram_size
    );
    fs::write(FILE_NAME, content).unwrap();
}
